package com.designlollipopdemo;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.designlollipopdemo.commonbar.CustomTitlebar;

public class NormalToolBarActivity extends AppCompatActivity {

    //toolbar 要求是 19
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_normal_tool_bar);
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        toolbar.setTitle("Title");
//        toolbar.setSubtitle("SubTitle");
//        toolbar.setLogo(R.mipmap.ic_launcher);
//        //设置导航图标要在setSupportActionBar方法之后
//        //setSupportActionBar(toolbar);
//        toolbar.setNavigationIcon(R.mipmap.back);

        initTitleBar();
    }

    //标题栏监听
    private void initTitleBar() {

        CustomTitlebar custombar = (CustomTitlebar) findViewById(R.id.custombar);
        custombar.setAction(new CustomTitlebar.TitleBarOnClickListener() {
            @Override
            public void performAction(View view) {
                switch (view.getId()) {
                    case R.id.iv_left:
                        NormalToolBarActivity.this.finish();
                        Toast.makeText(NormalToolBarActivity.this, "左边区域", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.iv_right:
                        Toast.makeText(NormalToolBarActivity.this, "右边区域", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
    }
}
